package com.yyr.callmessage.core.ro;


import com.yyr.callmessage.core.config.LocaleConfig;
import com.yyr.callmessage.core.constant.SystemError;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.context.i18n.LocaleContextHolder;

@Getter
@Setter
@ToString
public class BaseRo {
    private String code = SystemError.SuccessCode; //响应码0为成功，系统错误则直接数字的字符串表示，比如-3表示token验证失败， 模块格式：模块-错误码
    private String msg = ""; //对应的响应描述

//    public boolean isSuccess() {
//        return code.equals(SystemError.SuccessCode);
//    }

    public void setMsg(String msg) {
        // 国际化
        this.msg = LocaleConfig.getMessageInstance().getMessage(msg, null, "", LocaleContextHolder.getLocale());
    }

    public BaseRo() {

    }

    // 本地化错误描述
    public BaseRo(String msg) {
        this(SystemError.ProcessCode, msg, true);
    }

    // 是否需要本地化错误描述
    public BaseRo(String msg, boolean isLocal) {
        this(SystemError.ProcessCode, msg, false);
    }

    // 本地化错误描述
    public BaseRo(String code, String msg) {
        this(code, msg, true);
    }

    // 是否需要本地化错误描述
    public BaseRo(String code, String msg, boolean isLocal) {
        if (isLocal) {
            setMsg(msg);
        } else {
            this.msg = msg;
        }
        setCode(code);
    }

}
